package cn.fl.rebacc.web.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.rebacc.web.service.ISaleRebAccInfoService;
import cn.fl.rebacc.web.transform.SaleRebAccInfoVOTransform;
import cn.fl.rebacc.web.vo.SaleRebAccInfoVO;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.spl.facade.rebacc.api.ISaleRebAccInfoApiService;
import fl.spl.facade.rebacc.condition.SaleRebAccInfoQC;
import fl.spl.facade.rebacc.dto.SaleRebAccInfoDTO;
import fl.spl.facade.spl.api.ISplInfoApiService;


/**
 * @Description: 公用销售返利账号信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SaleRebAccInfoServiceImpl implements ISaleRebAccInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(SaleRebAccInfoServiceImpl.class);
	
	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	//@Autowired
	//private I自定义ApiService 自定义ApiService;

	@Autowired
	private ISaleRebAccInfoApiService saleRebAccInfoApiService ;
	
	@Autowired
	private ISplInfoApiService splInfoApiService ;
	@Override
	public SaleRebAccInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		SaleRebAccInfoDTO dto = this.saleRebAccInfoApiService.selectById(id);
		return SaleRebAccInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(SaleRebAccInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不存在!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"新增对象不存在!");
		};
		return this.saleRebAccInfoApiService.add(SaleRebAccInfoVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentBuOrgCd(),
				CurrentThreadContext.getCurrentOrgCd(),
				CurrentThreadContext.getCurrentSysCd());
		//TODO 业务逻辑
		//return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除对象主键不能为空!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
		};
		//return this.saleRebAccInfoApiService.removeSaleRebAccInfoDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(SaleRebAccInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象不能为空!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"修改对象不能为空!");
		};
		return this.saleRebAccInfoApiService.modify(SaleRebAccInfoVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentOrgCd(),CurrentThreadContext.getCurrentSysCd());
		//TODO 业务逻辑
		//return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		Pager pager = this.saleRebAccInfoApiService.searchListPage(page);
		if(pager != null){
			List<SaleRebAccInfoDTO> dtoList = (List<SaleRebAccInfoDTO>)pager.getResultList();
			List<SaleRebAccInfoVO> voList = SaleRebAccInfoVOTransform.toVOList(dtoList);
			pager.setResultList(voList);
		}
		return pager ;
	}

	@Override
	public DataResultDTO addSplAdmissionFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException {
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.info(logger, "addSplAdmissionFlowStart", "用户ID和业务数据主键必须要存在!",CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "用户ID和业务数据主键必须要存在!");
		}
		return this.saleRebAccInfoApiService.addFlowStart(flowStartParamsDTO);
	}
	@Override
	public List<SaleRebAccInfoVO> searchList(SaleRebAccInfoQC condition) throws BaseException {
		// TODO Auto-generated method stub
		if(condition == null){
			condition = new SaleRebAccInfoQC();
		}
		List<SaleRebAccInfoDTO> searchList = this.saleRebAccInfoApiService.searchList(condition);
		 
		return SaleRebAccInfoVOTransform.toVOList(searchList);
	}
}
